package com.example.archivemanagement.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.archivemanagement.entity.Archive;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Mapper
public interface ArchiveMapper extends BaseMapper<Archive> {
    @Results({
            @Result(property = "key", column = "security_level"),
            @Result(property = "value", column = "count")
    })
    @Select("SELECT security_level, COUNT(security_level) AS count FROM sys_archive GROUP BY security_level")
    List<Map<String, Object>> countByLevelList();

    default Map<String, Long> countByLevel() {
        return countByLevelList().stream()
                .collect(Collectors.toMap(
                        map -> String.valueOf(map.get("key")),
                        map -> Long.valueOf(String.valueOf(map.get("value")))
                ));
    }
}